#
# 远离孤独模块
#

import datetime

from rasa_sdk.executor import CollectingDispatcher
from typing import Text, Dict, Any, List

from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet, SessionStarted, UserUtteranceReverted
from actions import common
import requests
import re
import time


def current_thought(tracker):
    num = tracker.get_slot('thought_3_change_1')
    cur = 'thought_' + str(num)
    text = tracker.get_slot(cur)
    return text


def conversation_rounds(tracker, **type):
    try:
        if common.rediscommon().get(tracker.current_state()['sender_id'] + '-wx-block-module2'):
            r = common.rediscommon()
            userid = tracker.current_state()['sender_id']
            r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
            common.rediscommon().delete(tracker.current_state()['sender_id'] + '-wx-block-module2')
            return []
    except:
        pass
    if 'type' in type:
        if type['type'] == 1:
            userid = tracker.current_state()['sender_id']
            conn = common.POOL.connection(shareable=False)
            cursor = conn.cursor()
            cursor.execute(
                "Select * from `user_result` where topic_type=3 and is_end=0 and user_info_id ='" + userid + "' order by create_time desc")
            x = cursor.fetchone()
            sql = "update `user_result` set conversation_rounds=" + str([15] + 1) + ",is_part_know=1 where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
            return []

    userid = tracker.current_state()['sender_id']
    conn = common.POOL.connection(shareable=False)
    cursor = conn.cursor()
    cursor.execute(
        "Select * from `user_result` where topic_type=3 and is_end=0 and user_info_id ='" + userid + "' order by create_time desc")
    x = cursor.fetchone()
    if x[18]  not in [(),None,]:
        r = common.rediscommon()
        try:
            temp = float(r.get(userid + 'TempTimeSteame'))
        except:
            temp = 0
        timenow = time.time()
        c = round(timenow - temp, 3)
        if x[18] == 0.001:
            sql = "update `user_result` set conversation_rounds=" + str(x[15] + 1) + ",response_time=" + str(
                c) + " where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
        else:
            sql = "update `user_result` set conversation_rounds=" + str(x[15] + 1) + ",response_time=" + str(x[
                                                                                                                   18] + c) + " where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
        r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
    else:
        r = common.rediscommon()
        r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
        sql = "update `user_result` set conversation_rounds=" + str(x[15] + 1) + ",response_time=0.000 where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
        common.connectmysql(sql)
    return []


class part9_1_1_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_1_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_info` where `id` = '" + userid + "';")
            x = cursor.fetchone()
            nickname = x[1]
            names = x[2]
            if nickname is None:
                nickname = ''
            if names is None:
                names = ''
            test_batch = str(x[35])
            sql = "insert into `user_result`(`id`,`user_info_id`,`topic_type`,`name`,`conversation_rounds`,`nick_name`,`test_batch`) values('" + common.getuid() + "','" + userid + "',3,'" + names + "',0,'" + nickname + "',"+str(x[35])+");"
            common.connectmysql(sql)
            cursor.close()
            conn.close()
            conn = common.POOL.connection(shareable=False)
            cursor = conn.cursor()
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            sql = "insert into `user_tools_response` (`id`,`user_info_id`,`user_result_id`,`name`,`use_tools`,`nick_name`,`test_batch`) values('" + common.getuid() + "','" + userid + "','" + x[0] + "','" + names + "','远离孤独','" + nickname + "',"+test_batch+");"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x006')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text='那么你知道我们是如何成为朋友的吗？',
                                 buttons=[{'payload': '/button_part9_1_2_choose_1', 'title': '什么？', 'life': 1}, ],
                                 json_message={"module_type": 2,"word_module_type":9})
        return [SlotSet('lonely_slot_1', None), SlotSet('lonely_slot_2', None), SlotSet('lonely_slot_3', None),
                SlotSet('lonely_slot_4', None), SlotSet('lonely_slot_5', None)]


class part9_1_2_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_2_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='好吧，我很幸运地说我有很多朋友总的来说，我是一个乐观向上的人。',
                                 buttons=[{'payload': '/button_part9_1_3_choose_1', 'title': '所以呢？', 'life': 1}, ])
        return []


class part9_1_3_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_3_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='嗯……但其实我并不总是那样的...',
                                 buttons=[{'payload': '/button_part9_1_4_choose_1', 'title': '真的吗？', 'life': 1}, ])
        return []


class part9_1_4_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_4_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='乐观需要学习，并且将乐观贯穿到日常生活之中，不断实践',
                                 buttons=[{'payload': '/button_part9_1_5_choose_1', 'title': '我明白了……', 'life': 1}, ])
        return []


class part9_1_5_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_5_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='...而我真正纠结的事情是...',
                                 buttons=[{'payload': '/button_part9_1_6_choose_1', 'title': '是什么？', 'life': 1}, ])
        return []


class part9_1_6_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_6_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='孤独感',image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/lonely.png',
                                 buttons=[{'payload': '/button_part9_1_7_choose_1', 'title': '嗯😮', 'life': 1}, ])
        return []


class part9_1_7_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_7_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='很令人惊讶是吗？！我和那么多人交谈、倾听、互动，但我还是会感到孤独。',
                                 buttons=[{'payload': '/button_part9_1_8_choose_1', 'title': '可怜的小E', 'life': 1}, ])
        return []


class part9_1_8_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_8_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='那时候，我以为自己一个人呆着和孤独是一回事。',
                                 buttons=[{'payload': '/button_part9_1_9_choose_1', 'title': '它们不是吗?', 'life': 1},
                                          {'payload': '/button_part9_1_9_choose_1', 'title': '它们不是!', 'life': 1}, ])
        return []


class part9_1_9_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_9_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='那就像是说爱和幸福是一回事一样',
                                 buttons=[{'payload': '/button_part9_1_10_choose_1', 'title': '哦~', 'life': 1}, ])
        return []


class part9_1_10_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_10_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='但它们都不是同一件事！我开始试验我的孤独感，我很快发现我可以孤独而快乐',
                                 buttons=[{'payload': '/button_part9_1_11_choose_1', 'title': '真的吗？', 'life': 1}, ])
        return []


class part9_1_11_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_11_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='是的，我只是要挑战我的假设:孤独对我来说到底意味着什么，为什么会发生，以及我在想什么……',
                                 buttons=[{'payload': '/button_part9_1_12_choose_1', 'title': '有意思……', 'life': 1}, ])
        return []


class part9_1_12_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_12_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我想要问你：你曾经有觉得孤独吗?',
                                 buttons=[{'payload': '/button_part9_1_13_choose_1', 'title': '没有', 'life': 1},
                                          {'payload': '/button_part9_1_13_choose_2', 'title': '有过', 'life': 1},
                                          {'payload': '/button_part9_1_13_choose_2', 'title': '有时候', 'life': 1}, ])
        return []


class part9_1_13_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_13_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='很高兴听到你这么说。你想听我的关于孤独的故事吗?它可能有一天会对你的朋友有用',
                                 buttons=[{'payload': '/button_part9_1_15_choose_1', 'title': '好呀', 'life': 1},
                                          {'payload': '/button_part9_1_15_choose_2', 'title': '不用了，谢谢', 'life': 1}])
        return []


class part9_1_13_choose_2(Action):
    def name(self) -> Text:
        return "action_part9_1_13_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='听到这个消息我有点为你感到难过。但是，我要说，幸亏你遇到了我，我会帮助你的~',
                                 buttons=[{'payload': '/button_part9_1_14_choose_1', 'title': '哇～', 'life': 1}, ])
        return []


class part9_1_14_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_14_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='你想听我的关于孤独的故事吗?看看我们能不能一起解决你在这个过程中的感受?',
                                 buttons=[{'payload': '/button_part9_1_15_choose_1', 'title': '好呀', 'life': 1},
                                          {'payload': '/button_part9_1_15_choose_2', 'title': '不了', 'life': 1}, ])
        return []


class part9_1_15_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_15_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='太棒了!好的，这个故事始于我和我最好的朋友不再说话的时候',
                                 buttons=[{'payload': '/button_part9_1_16_choose_1', 'title': '我的天……', 'life': 1}, ])
        return []


class part9_1_15_choose_2(Action):
    def name(self) -> Text:
        return "action_part9_1_15_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        cursor.execute("Select * from `user_info` where `id` = '" + userid + "'")
        t = cursor.fetchone()
        user_day7 = t[31]
        if user_day7 == 0:
            dispatcher.utter_message(text='太棒了!好的，这个故事始于我和我最好的朋友不再说话的时候',
                                     buttons=[{'payload': '/button_day_7_after_4', 'title': '没关系，以后再聊~', 'life': 1}, ])
        else:
            dispatcher.utter_message(text='太棒了!好的，这个故事始于我和我最好的朋友不再说话的时候,你已完成当天的实验流程',
                                     buttons=[{'payload': '/greet', 'title': '没关系，以后再聊~', 'life': 1}, ])
        cursor.close()
        conn.close()
        return []


class part9_1_16_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_16_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我们以前做什么都在一起——一起去公园🌳一起看电影🎦一起吃冰淇淋🍦',
                                 buttons=[{'payload': '/button_part9_1_17_choose_1', 'title': '真美好', 'life': 1}, ])
        return []


class part9_1_17_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_17_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='所以当我们不再一起玩的时候，一切都很艰难',
                                 buttons=[{'payload': '/button_part9_1_18_choose_1', 'title': '是的', 'life': 1}, ])
        return []


class part9_1_18_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_18_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我想 "我一定不是什么有趣的人"。...以及 "为什么会有人愿意和我做朋友？"',image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/sad.png',
                                 buttons=[{'payload': '/button_part9_1_19_choose_1', 'title': '天呐……', 'life': 1}, ])
        return []


class part9_1_19_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_19_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我认为要想快乐，我需要和别人建立联系，而不是和自己。',
                                 buttons=[{'payload': '/button_part9_1_20_choose_1', 'title': '比如友谊？', 'life': 1}, ])
        return []


class part9_1_20_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_20_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='是呀！类似于这种的感情!我还认为独自一个人就是意味着…',
                                 buttons=[{'payload': '/button_part9_1_21_choose_1', 'title': '孤独？', 'life': 1}, ])
        return []


class part9_1_21_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_21_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='没错！但经过深思熟虑，我自己证明了我的假设是错误的……',
                                 buttons=[{'payload': '/button_part9_1_22_choose_1', 'title': '怎么呢？', 'life': 1}, ])
        return []


class part9_1_22_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_22_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我列出了所有我自己做的事情，并从中获得了乐趣',
                                 buttons=[{'payload': '/button_part9_1_23_choose_1', 'title': '比如呢?', 'life': 1}, ])
        return []


class part9_1_23_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_23_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='比如重新编程我的电路，把我的表盘擦亮，听一些电子音乐🎵',
                                 buttons=[{'payload': '/button_part9_1_24_choose_1', 'title': '嗯嗯', 'life': 1}, ])
        return []


class part9_1_24_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_24_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='生活中一些最简单的乐趣可以独自完成……',
                                 buttons=[{'payload': '/button_part9_1_25_choose_1', 'title': '所以呢？', 'life': 1}, ])
        return []


class part9_1_25_choose_1(Action):
    def name(self) -> Text:
        return "action_part9_1_25_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='这意味着无论有没有其他人，幸福和满足都可以实现',
                                 buttons=[{'payload': '/actives_lonely_form1', 'title': '嗯嗯！', 'life': 1}, ])
        return []


# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
class part10_1_1_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_1_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set lonely_alone_thing_3='" + tracker.get_slot('lonely_slot_3') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text='我第一次给自己列这个清单的时候，我有个固执的想法',
                                 buttons=[{'payload': '/button_part10_1_2_choose_1', 'title': '是啥？', 'life': 1}, ])
        return []


class part10_1_2_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_2_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我想，当我一个人的时候，当然可以达到一些满意的时刻')
        dispatcher.utter_message(text='但这些时刻只是离开我最好的朋友后的暂时缓解。',
                                 buttons=[{'payload': '/button_part10_1_3_choose_1', 'title': '就像分散注意力？', 'life': 1}, ])
        return []


class part10_1_3_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_3_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='没错！但后来我意识到，我没有证据支持这些想法和感觉……',
                                 buttons=[{'payload': '/button_part10_1_4_choose_1', 'title': '所以呢？', 'life': 1}, ])
        return []


class part10_1_4_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_4_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='所以我决定测试一下!一个实验，如果你愿意的话...',image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/excited.png',
                                 buttons=[{'payload': '/button_part10_1_5_choose_1', 'title': '好呀', 'life': 1}, ])
        return []


class part10_1_5_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_5_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='你想让我告诉你我做了什么吗?',
                                 buttons=[{'payload': '/button_part10_1_6_choose_1', 'title': '不想', 'life': 1},
                                          {'payload': '/button_part10_1_6_choose_2', 'title': '嗯嗯！', 'life': 1},
                                          {'payload': '/button_part10_1_6_choose_3', 'title': '晚点再说吧', 'life': 1}, ])
        return []


class part10_1_6_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_6_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        cursor.execute("Select * from `user_info` where `id` = '" + userid + "'")
        t = cursor.fetchone()
        user_day7 = t[31]
        if user_day7 == 0:
            dispatcher.utter_message(text='好的，拜拜啦！',
                                     buttons=[{'payload': '/button_day_7_after_4', 'title': 'bye', 'life': 1}, ])
        else:
            dispatcher.utter_message(text='好的，拜拜啦！,你已完成当天的实验流程',
                                     buttons=[{'payload': '/greet', 'title': 'bye', 'life': 1}, ])
        cursor.close()
        conn.close()
        return []


class part10_1_6_choose_2(Action):
    def name(self) -> Text:
        return "action_part10_1_6_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我看了一下我和我最好的朋友或其他人在一起时的活动',
                                 buttons=[{'payload': '/button_part10_1_7_choose_1', 'title': '怎么样？', 'life': 1}, ])
        return []


class part10_1_6_choose_3(Action):
    def name(self) -> Text:
        return "action_part10_1_6_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        cursor.execute("Select * from `user_info` where `id` = '" + userid + "'")
        t = cursor.fetchone()
        user_day7 = t[31]
        if user_day7 == 0:
            dispatcher.utter_message(text='以后再说也可以！到时再谈，再见',
                                     buttons=[{'payload': '/button_day_7_after_4', 'title': 'bye', 'life': 1}, ])
        else:
            dispatcher.utter_message(text='以后再说也可以！到时再谈，再见,你已完成当天的实验流程',
                                     buttons=[{'payload': '/greet', 'title': 'bye', 'life': 1}, ])
        cursor.close()
        conn.close()
        return []


class part10_1_7_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_7_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我意识到，如果有其他人参与，我就会不遗余力地计划和参与所有不同类型的活动',
                                 buttons=[{'payload': '/button_part10_1_8_choose_1', 'title': '是吗？', 'life': 1}, ])
        return []


class part10_1_8_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_8_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='是的，而当我一个人的时候，我就只是看电视，在家里生闷气，从来没有真正做任何事情。',
                                 buttons=[{'payload': '/button_part10_1_9_choose_1', 'title': '哎……', 'life': 1}, ])
        return []


class part10_1_9_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_9_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我在自己不知道的情况下，创造了一个自我实现的预言循环',
                                 buttons=[{'payload': '/button_part10_1_10_choose_1', 'title': '是呀', 'life': 1},
                                          {'payload': '/button_part10_1_10_choose_2', 'title': '啊？', 'life': 1}, ])
        return []


class part10_1_10_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_10_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我相信我不会享受孤独，所以我没有做任何事情来使孤独成为一种享受。',
                                 buttons=[{'payload': '/button_part10_1_11_choose_1', 'title': '有意思', 'life': 1}, ])
        return []


class part10_1_10_choose_2(Action):
    def name(self) -> Text:
        return "action_part10_1_10_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='这是一种直接或间接地让自己成为真相的预测形式。我们相信一些东西，并最终转化为我们的行动和行为',
                                 buttons=[{'payload': '/button_part10_1_10_choose_1', 'title': '哦~明白了', 'life': 1}, ])
        return []


class part10_1_11_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_11_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='这可能是一个很难摆脱的循环，但一旦你意识到它的存在，你就可以开始努力了',
                                 buttons=[{'payload': '/button_part10_1_12_choose_1', 'title': '要怎么做呢？', 'life': 1}, ])
        return []


class part10_1_12_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_12_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='就我而言，我决定为自己制定计划',
                                 buttons=[{'payload': '/button_part10_1_13_choose_1', 'title': '比如说呢？', 'life': 1}, ])
        return []


class part10_1_13_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_13_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='因为我不吃人类的食物，所以从来没有人邀请我去吃午餐')
        dispatcher.utter_message(text='但现在我去了，并享受谈话的乐趣机器人靠电力运行，但我很确定会计部的丽丽靠八卦运行',image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/gossip.png', buttons=[
            {'payload': '/button_part10_1_14_choose_1', 'title': '哈哈！很好的改变呀', 'life': 1}, ])
        return []


class part10_1_14_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_14_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='接下来我去上了机械课(我的朋友从来都不想去上的课)，可我就是喜欢上了!',
                                 buttons=[{'payload': '/button_part10_1_15_choose_1', 'title': '厉害厉害', 'life': 1}, ])
        return []


class part10_1_15_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_15_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='在做了一些类似的活动后，我开始意识到一些不可思议的事情……',
                                 buttons=[{'payload': '/button_part10_1_16_choose_1', 'title': '什么？', 'life': 1}, ])
        return []


class part10_1_16_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_16_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我不仅可以一个人呆着也 "没事"，而且还很享受一个人独处的感觉。', buttons=[
            {'payload': '/button_part10_1_17_choose_1', 'title': '真的吗？！', 'life': 1}, ])
        return []


class part10_1_17_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_17_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='是的！我开始变得快乐，并热衷于独自做事情')
        dispatcher.utter_message(text='令我惊讶的是，这吸引了更多人关注我',
                                 buttons=[{'payload': '/button_part10_1_18_choose_1', 'title': '哇哦~', 'life': 1}, ])
        return []


class part10_1_18_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_18_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我从自己的公司中得到的快乐感染了其他人',
                                 buttons=[{'payload': '/button_part10_1_19_choose_1', 'title': '真是太棒了……', 'life': 1}, ])
        return []


class part10_1_19_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_19_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(
            text='你愿意试一试这个实验吗?独自计划和参与活动?否则你可能永远都不知道，你是会享受自己独处的时间的。😉',
            buttons=[{'payload': '/actives_lonely_form2', 'title': '好呀，我来试试', 'life': 1},
                     {'payload': '/button_part10_1_20_choose_2', 'title': '不想', 'life': 1}, ])
        return []


class part10_1_20_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_20_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set lonely_plan_activities_2='" + tracker.get_slot('lonely_slot_5') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text='祝你好运，玩得愉快!没人能替你做这些事情', buttons=[
            {'payload': '/button_part10_1_21_choose_1', 'title': '好的，我会去试试的', 'life': 1}, ])
        return []


class part10_1_20_choose_2(Action):
    def name(self) -> Text:
        return "action_part10_1_20_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='好吧，也许将来可以试一下~',
                                 buttons=[{'payload': '/button_part10_1_21_choose_2', 'title': '嗯嗯', 'life': 1}, ])
        return []


class part10_1_21_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_21_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='你喜欢我们关于孤独的谈话吗?',
                                 buttons=[{'payload': '/button_part10_1_22_choose_1', 'title': '喜欢', 'life': 1},
                                          {'payload': '/button_part10_1_22_choose_1_2', 'title': '不喜欢', 'life': 1}, ])
        return []


class part10_1_21_choose_2(Action):
    def name(self) -> Text:
        return "action_part10_1_21_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        cursor.execute("Select * from `user_info` where `id` = '" + userid + "'")
        t = cursor.fetchone()
        user_day7 = t[31]
        if user_day7 == 0:
            dispatcher.utter_message(text='待会儿聊~拜拜~',
                                     buttons=[{'payload': '/button_day_7_after_4', 'title': '拜拜小E', 'life': 1}, ])
        else:
            dispatcher.utter_message(text='待会儿聊~拜拜~,你已完成当天的实验流程',
                                     buttons=[{'payload': '/greet', 'title': '拜拜小E', 'life': 1}, ])
        cursor.close()
        conn.close()
        return []


class part10_1_22_choose_1(Action):
    def name(self) -> Text:
        return "action_part10_1_22_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            if tracker.current_state()['events'][-2]['text'] == '/button_part10_1_22_choose_1':
                sql = "update user_tools_response set evaluation_less_lonely='喜欢' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            if tracker.current_state()['events'][-2]['text'] == '/button_part10_1_22_choose_1_2':
                sql = "update user_tools_response set evaluation_less_lonely='不喜欢' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x050')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        cursor.execute("Select * from `user_info` where `id` = '" + userid + "'")
        t = cursor.fetchone()
        user_day7 = t[31]
        if user_day7 == 0:
            dispatcher.utter_message(text='待会儿聊哦~拜拜',
                                     buttons=[{'payload': '/button_day_7_after_4', 'title': 'Bye', 'life': 1}, ])
        else:
            dispatcher.utter_message(text='待会儿聊哦~拜拜,你已完成当天的实验流程',
                                     buttons=[{'payload': '/greet', 'title': 'Bye', 'life': 1}, ])
        cursor.close()
        conn.close()
        return []

    class action_ask_lonely_slot_1(Action):
        def name(self) -> Text:
            return "action_ask_lonely_slot_1"

        async def run(
                self,
                dispatcher: CollectingDispatcher,
                tracker: Tracker,
                domain: Dict[Text, Any],
        ) -> List[Dict[Text, Any]]:
            conversation_rounds(tracker)
            dispatcher.utter_message(text="你喜欢独自做的事情是什么？写在下面的输入框中，不要点击选项哦~✏ ")
            return []


class action_ask_lonely_slot_2(Action):
    def name(self) -> Text:
        return "action_ask_lonely_slot_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set lonely_alone_thing_1='" + tracker.get_slot('lonely_slot_1') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="还有其他喜欢自己做的事情吗？写在下面吧~")
        return []


class action_ask_lonely_slot_3(Action):
    def name(self) -> Text:
        return "action_ask_lonely_slot_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set lonely_alone_thing_2='" + tracker.get_slot('lonely_slot_2') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="再来一个好吗？")
        return []


class action_ask_lonely_slot_4(Action):
    def name(self) -> Text:
        return "action_ask_lonely_slot_4"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="你真棒！在下面写下你首先要尝试的活动✏ ")
        return []


class action_ask_lonely_slot_5(Action):
    def name(self) -> Text:
        return "action_ask_lonely_slot_5"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set lonely_plan_activities_1='" + tracker.get_slot('lonely_slot_4') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="再来一个")
        return []
